package prolog.terms

final case class Conj(h: Term, b: Term)
  extends Fun(",", Array(h, b)) {

  def getHead = args(0).ref
  def getBody = args(1).ref

  override def toString = getHead + "," + getBody
}

object Conj {

  final def build(x: Term, y: Term) = Conj(x, y)

  final def fromList(xs: List[Term]): Term = xs.reduceRight[Term](build)

  final def toList(t: Term): List[Term] = t match {
    case Conj(x, xs) => x :: toList(xs)
    case x: Term => List(x)
  }

}